//
//  RequstMusic.m
//  Leisure
//
//  Created by xalo on 16/7/4.
//  Copyright © 2016年 朱旭东. All rights reserved.
//

#import "RequstMusic.h"
@interface RequstMusic ()
@property(nonatomic,strong)NSMutableArray *musicArray;
@end

@implementation RequstMusic


- (NSMutableArray *)musicArray
{
    if (!_musicArray) {
        _musicArray = [NSMutableArray array];
    }
    return _musicArray ;
}

//单利
+(instancetype)defaultManager{
    static RequstMusic *handle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        handle= [[RequstMusic alloc]init];
    });
    return handle;
}

//通过url获取数据
-(void)fetchDataWithurl:(NSString *)url  updataUI:(RadioMusicBloock)block{
    //子线程:用来处理耗时操作
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        NSArray *array = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:url]];
        for (NSDictionary *dic in array) {
            RadioListModel *model = [[RadioListModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.musicArray addObject:model];
        }
        //主线程
        dispatch_async(dispatch_get_main_queue(), ^{
            NSLog(@"刷新UI");
            block();
        });
        
    });

}

//返回数据个数
- (NSInteger)retureArrayCount{
    return self.musicArray.count;
}

//返回对应下标的模型
- (RadioListModel *)returnMusicAtIndex:(NSInteger)index{
    return self.musicArray[index];
}



@end
